package homework;

import java.util.Scanner;

public class Calculator {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入运算数字：");
        int a = scanner.nextInt();
        boolean s = true;
        int value = a;
        String symbol="";
        while (s) {
            System.out.println("请输入运算符：");
            symbol = scanner.next();//JDK1.7+支持
            switch (symbol) {
                case "*":
                    System.out.println("请输入运算数字：");
                    a = scanner.nextInt();
                    value *= a;
                    System.out.println( value);
                    break;
                case "-":
                    System.out.println("请输入运算数字：");
                    a = scanner.nextInt();
                    value -= a;
                    System.out.println( value);
                    break;
                case "/":
                    System.out.println("请输入运算数字：");
                    a = scanner.nextInt();
                    try{
                        value /= a;
                    }catch(Exception e){
                        System.out.println("请输入非零数字：");
                        a = scanner.nextInt();
                        value /= a;
                }
                    System.out.println(value);
                    break;
                case "+":
                    System.out.println("请输入运算数字：");
                    a = scanner.nextInt();
                    value += a;
                    System.out.println(value);
                    break;
                case "=":
                    s = false;
                    System.out.println("最终结果是:"+value);
                    break;
                default:
                    System.out.print("输入错误，");
            }
        }
    }
}
